package com.ruoyi.carbon.service.impl;

import com.ruoyi.carbon.domain.vo.PandianVo;
import com.ruoyi.carbon.entity.PandianInfo;
import com.ruoyi.carbon.entity.Wuliao;
import com.ruoyi.carbon.mapper.PandianInfoMapper;
import com.ruoyi.carbon.service.PandianInfoService;
import com.ruoyi.common.exception.ServiceException;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PandianInfoServiceImpl implements PandianInfoService {

    @Autowired
    private PandianInfoMapper pandianInfoMapper;

    @Override
    public List<PandianVo> list(PandianVo pandianVo) {


        return pandianInfoMapper.list(pandianVo);
    }

    @Override
    public int remove(List<Long> ids) {

        if (ObjectUtils.isEmpty(ids)) throw new ServiceException("请选择要删除的数据");

        return pandianInfoMapper.remove(ids);
    }

    @Override
    public int saveOrUpdate(PandianVo pandianVo) {

        PandianInfo pandianInfo = pandianVo.getPandianInfo();
        pandianInfo.setWuliaoId(pandianVo.getWuliao().getId());

        int num = 0;

        Long id = pandianInfo.getId();
        if (id == null) {
            num = pandianInfoMapper.save(pandianInfo);
        } else {
            num = pandianInfoMapper.edit(pandianInfo);
        }

        return num;
    }

    @Override
    public PandianVo getById(Long id) {
        return pandianInfoMapper.getById(id);
    }
}
